# 定义函数来将 dcm 文件转换为 nii.gz 文件

# 遍历文件夹 A 下的所有三级子文件夹
$folderPath = "F:\MedAi\pancreas_all"
$dstFolderPath = "F:\MedAi\pancreas_ok\images"

$level1Folders = Get-ChildItem -Path $folderPath -Directory

# 病人
foreach ($level1Folder in $level1Folders) {
    $level2Folders = Get-ChildItem -Path $level1Folder.FullName -Directory

    #  MR
    foreach ($level2Folder in $level2Folders) {
        $level3Folders = Get-ChildItem -Path $level2Folder.FullName -Directory

        # DWI
        foreach ($level3Folder in $level3Folders) {
            # 情况2 ：
            # 文件名： 病人+序列
            $file_name = $level1Folder.Name + "+" + $level3Folder.Name


            # dcm2niix -o [输出文件夹] -z y -f [文件名]  [输入文件夹]
            # -b n: no json
            dcm2niix -b n -ba n -o $dstFolderPath -z y -f $file_name -s y $level3Folder.FullName
        }
        # break
    }
    # break
}
